/*
 * BlackLightning.PluginLib.Modules.WizardPacket
 * Andy Tidball
 * 
 * Project: Black Lightning Plugin Library
 * Copyright: GNU General Public License
 */

using System;
using BlackLightning.PluginLib;
using BLLib.Net;

namespace BlackLightning.PluginLib.Modules {
	/// <summary>
	/// A packet that is used exclusively with the Wizard front end.
	/// </summary>
	[Serializable]
	public class WizardPacket : CommonFEPacket {
		/// <summary>
		/// Creates a new WizardPacket.
		/// </summary>
		/// <param name="Source">The Program that created the packet.</param>
		/// <param name="Destination">The Program to which the packet will be delivered.</param>
		/// <param name="Data">The raw data string to contain in the packet.</param>
		public WizardPacket(Program Source, Program Destination, string Data)
			: base(Source, Destination, Data) {
		}

		/// <summary>
		/// Creates a new WizardPacket.
		/// </summary>
		/// <param name="Source">The Program that created the packet.</param>
		/// <param name="Destination">The Program to which the packet will be delivered.</param>
		/// <param name="Data">The raw data string to contain in the packet.</param>
		/// <param name="Context">Context about where the packet came from.</param>
		internal WizardPacket(Program Source, Program Destination, string Data, BLPacketContext Context)
			: base(Source, Destination, Data, Context) {
		}

		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="P">The WizardPacket to create a copy of.</param>
		/// <param name="DeepCopyOrNextState">True to make a deep copy of the given packet, false to instead use the given packet as the new packet's previous state.</param>
		internal WizardPacket(WizardPacket P, bool DeepCopyOrNextState)
			: base(P, DeepCopyOrNextState) {
		}

		/// <summary>
		/// Retrieves the packet's data.
		/// </summary>
		/// <param name="Context">Contextual information to use to create output from the packet's data.</param>
		/// <returns>A string representing the packet's data.</returns>
		public override string CreateOutput(PacketContext Context) {
			return base.CreateOutput(Context);
		}

		/// <summary>
		/// Creates a deep copy of the packet.
		/// </summary>
		/// <returns>A deep copy of the packet.</returns>
		public override object Clone() {
			return new WizardPacket(this, true);
		}

		/// <summary>
		/// Creates a new WizardPacket that has this WizardPacket as its PreviousState.
		/// </summary>
		/// <returns>A new WizardPacket that has this one as its PreviousState.</returns>
		internal override BLPacket GetNextState() {
			return new WizardPacket(this, false);
		}
	}

	/// <summary>
	/// A BLPacketFilter to use with WizardPackets.
	/// </summary>
	[Serializable]
	public class WizardPacketFilter : CommonFEPacketFilter {
		/// <summary>
		/// Creates a new WizardPacketFilter.
		/// </summary>
		public WizardPacketFilter() {
		}

		/// <summary>
		/// Creates a new WizardPacketFilter.
		/// </summary>
		/// <param name="Source">The source program to match against the packet's source.</param>
		/// <param name="Destination">The destination program to match against the packet's destination.</param>
		public WizardPacketFilter(Program Source, Program Destination)
			: base(Source, Destination) {
		}

		/// <summary>
		/// Matches the packet's dynamic data against the filter.
		/// </summary>
		/// <param name="Packet">The packet to match against the filter.</param>
		/// <returns>True if the packet's dynamic data matches the current setup of the filter, false if it does not.</returns>
		public override bool DynamicMatch(BLPacket Packet) {
			// make sure this is a WizardPacket
			WizardPacket P = Packet as WizardPacket;
			if (P == null) {
				return false;
			}

			// everything passed, match the base packet data
			return base.DynamicMatch(P);
		}
	}
}
